package com.hamilton.erik.pt.mobile.android.volley.response.error.listener;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.android.volley.Response.ErrorListener;
import com.android.volley.VolleyError;

public class DisplayErrorErrorListener implements ErrorListener {

	private Context context;
	private ProgressDialog progressDialog;
	
	public DisplayErrorErrorListener(Context context) {
		this.context = context;
		this.progressDialog = null;
	}
	
	public DisplayErrorErrorListener(Context context, ProgressDialog progressDialog) {
		this.context = context;
		this.progressDialog = progressDialog;
	}
	
	@Override
	public void onErrorResponse(VolleyError error) {
		if(progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
		}
		
		AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setMessage("An error has occured: " + error.toString());
        adb.setCancelable(false);
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
			}
        });
        adb.show();
	}

}
